import { defineStore } from 'pinia'
import request from '@/utils/request'
import { ApiRes } from '@/types/data'
import {Profile} from '@/types/user'


export default defineStore('user',{
  state() {
    return {
      profile:{} as Profile
    }
  },
  actions: {
  async  login(data:{account:string,password:string}){
      const res = await request.post<ApiRes<Profile>>('/login',data)
      this.profile = res.data.result
    },
    // 获取手机验证码
async sendMobileMsg(mobile: string) {
  await request.get('/login/code', {
    params: {
      mobile
    }
  })
},
async mobileLogin(data: { mobile: string, code: string }) {
  const res = await request.post<ApiRes<Profile>>('/login/code', data)
  // 1. 保存用户信息到 state 中
  this.profile = res.data.result
},
  }
})